#!/usr/bin/env python
# coding=utf8

from flask import jsonify
from flask import request

from . import manager
from app.service.manager import Manager
from app.common.exception import ServiceError


@manager.route("/user", methods=['POST'])
def add_user():
    params = request.get_json()

    try:
        uid = Manager.add_user(params)

        code = 200
        data = {
            "status" : "success",
            "uid" : uid
        }
    except ServiceError as e:
        code = e.code
        data = e.message
    except Exception as e:
        code = 500
        data = e.message
    finally:
        pass

    return jsonify({"code" : code, "data" : data})
